package com.aistar.service.myfoot.impl;

import com.aistar.mapper.TravelnoteMapper;
import com.aistar.pojo.Travelnote;
import com.aistar.pojo.TravelnoteExample;
import com.aistar.service.myfoot.MyTravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
 * @author shkstart
 * @date 2019/10/5 - 19:24
 */
@Service
public class MyTravelServiceImpl implements MyTravelService {
    @Autowired
    private TravelnoteMapper travelnoteMapper;
    @Override
    public int countOfNote(int userId) {
        TravelnoteExample travelnoteExample = new TravelnoteExample();
        TravelnoteExample.Criteria criteria = travelnoteExample.createCriteria();
        criteria.andTravWidEqualTo(userId);
        return travelnoteMapper.countByExample(travelnoteExample);
    }

    @Override
    public int countOfReply(int id) {

        return 0;
    }

    @Override
    public int countOfRead(int id) {
        return 0;
    }

    @Override
    public int countVisited(int userId) {
        TravelnoteExample travelnoteExample = new TravelnoteExample();
        TravelnoteExample.Criteria criteria = travelnoteExample.createCriteria();
        criteria.andTravWidEqualTo(userId);
        List<Travelnote> list= travelnoteMapper.selectByExample(travelnoteExample);
        int sum = 0;
        Iterator<Travelnote> iterator = list.iterator();
        while (iterator.hasNext()){
           Travelnote travelnote = iterator.next();
           sum += travelnote.getTravLooknumber();
        }
        return sum;
    }

    @Override
    public Travelnote selectNoteById(int travId) {
        return travelnoteMapper.selectByPrimaryKey(travId);
    }


}
